package com.ruralflow.common.config;

import com.ruralflow.common.config.properties.Tess4jProperties;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.tess4j.Tesseract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置一个可供操作的tess4j对象
 */
@Configuration
@Slf4j
public class Tess4jConfig {

    // 配置类
    private final Tess4jProperties tess4jProperties;

    // 使用构造函数注入
    public Tess4jConfig(Tess4jProperties tess4jProperties) {
        this.tess4jProperties = tess4jProperties;
    }

    @Bean
    public Tesseract tesseract() {
        Tesseract instance = new Tesseract();
        instance.setLanguage(tess4jProperties.getLanguage()); // 设置语言包，这里使用简体中文
        instance.setDatapath(tess4jProperties.getDatapath()); // 设置语言包路径
        log.info("tess4j配置成功!");
        return instance;
    }


}